/*!
*
*/

注册
$("#regForm").validate({
    rules: {
        bdzcUserName: {
            required: true,
            minlength: 11,
            isMobile: true
        },
        bdzcSmsCode: {
            required: true,
            minlength: 6,
            maxlength: 6
        },
        bdzcUserPassword: {
            required: true,
            minlength: 6,
            maxlength: 16
        },
        bdzcUserConfirmPassword: {
            equalTo: "#bdzcUserPassword"
        },
        regAgree: "required",

    },
    messages: {
        bdzcUserName: {
            required: "请输入手机号",
            minlength: "长度为11位",
            isMobile: "请正确填写您的手机号码"
        },
        bdzcSmsCode: {
            required: "请输入验证码",
            minlength: "输入6位验证码",
            maxlength: "输入6位验证码"
        },
        bdzcUserPassword: {
            required: "请输入密码",
            minlength: "最少6位",
            maxlength: "最多16位"
        },
        bdzcUserConfirmPassword: {
            required: "请再次输入密码",
            minlength: "密码长度不能小于 6 位",
            equalTo: "两次密码输入不一致"
        },
        regAgree:
            "请同意协议",
    },
    submitHandler: function (form) { //通过之后回调
        //进行ajax传值
        $.ajax({
            url: "{:U('user/index')}",
            type: "post",
            dataType: "json",
            data: {
                user: $("#bdzcUserName").val(),
                password: $("#bdzcUserPassword").val()
            },
            success: function (msg) {
                //要执行的代码
            }
        });
    },
    invalidHandler: function (form, validator) {
        return false;
    },
    // errorElement: "em",
    // errorPlacement: function (error, element) {
    //     // Add the `help-block` class to the error element
    //     error.addClass("help-block");
    //
    //     // Add `has-feedback` class to the parent div.form-group
    //     // in order to add icons to inputs
    //     element.parents(".col-md-5").addClass("has-feedback");
    //
    //     if (element.prop("type") === "checkbox") {
    //         error.insertAfter(element.parent("label"));
    //     } else {
    //         error.insertAfter(element);
    //     }
    //
    //     // Add the span element, if doesn't exists, and apply the icon classes to it.
    //     if (!element.next("span")[0]) {
    //         $("<span class='glyphicon glyphicon-remove form-control-feedback'></span>").insertAfter(element);
    //     }
    // },
    // success: function (label, element) {
    //     // Add the span element, if doesn't exists, and apply the icon classes to it.
    //     if (!$(element).next("span")[0]) {
    //         $("<span class='glyphicon glyphicon-ok form-control-feedback'></span>").insertAfter($(element));
    //     }
    // },
    // highlight: function (element, errorClass, validClass) {
    //     $(element).parents(".col-md-5").addClass("has-error").removeClass("has-success");
    //     $(element).next("span").addClass("glyphicon-remove").removeClass("glyphicon-ok");
    // },
    // unhighlight: function (element, errorClass, validClass) {
    //     $(element).parents(".col-md-5").addClass("has-success").removeClass("has-error");
    //     $(element).next("span").addClass("glyphicon-ok").removeClass("glyphicon-remove");
    // }
});
//60S获取验证码
$("#bdzcBtnSmsCode").click(function () {
    if ($("#bdzcUserName").valid() != "") {
        bdzcSettime(this)
    }
});
var bdzcCount = 60;

function bdzcSettime(obj) {
    if (bdzcCount == 0) {
        obj.removeAttribute("disabled");
        obj.value = "免费获取验证码";
        bdzcCount = 60;
        return;
    } else {
        obj.setAttribute("disabled", true);
        obj.value = "重新发送(" + bdzcCount + ")";
        bdzcCount--;
    }
    setTimeout(function () {
            bdzcSettime(obj)
        }
        , 1000)
}

//模态框默认背景键盘不能点击
$('.bdzcModalContract').modal({backdrop: 'static', keyboard: false, show: true});

//阅读合同条款指定时间
function bdzcRunTimer(k) {
    $(".bdzcCloseTerms").html("倒计时: <b class='fontRed'>" + k + "</b>S后可以关闭");
    k--;
    if (k >= 0) {
        timer = setTimeout(function () {
            RunTimer(k)
        }, 1000);
    }
    else {
        $(".bdzcCloseTerms").hide();
        $(".bdzcCloseTerms").next("button").attr("data-dismiss", "modal");
    }
};
bdzcRunTimer(0);//调用倒计时

// 手机号码验证
jQuery.validator.addMethod("isMobile", function (value, element) {
    var length = value.length;
    var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
    return this.optional(element) || (length == 11 && mobile.test(value));
}, "请正确填写您的手机号码");